﻿using AutoMapper;
using Ducu.BLL.Entity;
using Ducu.SRV.ViewModel.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity = Ducu.BLL.Entity;
using Plan = Ducu.SRV.ViewModel.Plan;
using Global.Core.ExtensionMethod;

namespace Ducu.SRV.ProdService.ViewModelMap
{
    internal class PlanModelMap
    {
        internal static void Init()
        {
            Mapper.CreateMap<Entity.Plan, NameIdModel>()
                .ForMember(s => s.Name,
                    opt => opt.MapFrom(p => p.Title))
                ;

            Mapper.CreateMap<Entity.Plan, Plan.Shared._ShowItemBodyModel>()
                .ForMember(s => s.FulfilWeekdays,
                    opt => opt.MapFrom(p => p.FulfilWeekdays.ToListIntDays()))
                ;

            Mapper.CreateMap<Plan.EditorTemplates._NewOrEditModel, Entity.Plan>()
                .ForMember(p=>p.To, opt=>opt.NullSubstitute(DateTime.Now.AddYears(1)))
                .ForMember(p => p.FulfilWeekdays,
                    opt => opt.MapFrom(n => n.FulfilWeekdays.ToStringDays()))
                .ForMember(p => p.KeyWords, opt => opt.Ignore())
                ;

            Mapper.CreateMap<Entity.Plan, Plan.EditorTemplates._NewOrEditModel>()
                .ForMember(n => n.FulfilWeekdays,
                    opt => opt.MapFrom(p => p.FulfilWeekdays.ToListIntDays()))
                .ForMember(n => n.KeyWords,
                    opt => opt.MapFrom(p => p.KeyWords.ToStringKeywords()))
                .ForMember(n => n.OptionalNumbersOfSupervisors, opt => opt.Ignore())
                ;

            Mapper.CreateMap<Entity.Plan, ViewModel.Shared.NameIdModel>()
                .ForMember(n => n.Name, opt => opt.MapFrom(p => p.Title))
                ;
        }
    }
}
